package com.xcf.queue;

import java.util.ArrayList;
import java.util.List;

/**
 * MyQueue <br>
 * 简单队列的实现
 *
 * @author xiaocf <br>
 * @version 1.0 <br>
 * @date 2020/6/24 20:08 <br>
 */
public class MyQueue<T> {

    private List<T> data;
    private int fontIndex;

    public MyQueue() {
        this.data = new ArrayList<>( );
        this.fontIndex = 0;
    }

    public MyQueue(int capacity) {
        this.data = new ArrayList<>(capacity);
        this.fontIndex = 0;
    }

    public boolean enQueue(T object) {
        data.add(object);
        return true;
    }

    public boolean deQueue() {
        if (isEmpty( )) {
            return false;
        }
        fontIndex++;
        return true;
    }

    public boolean isEmpty() {
        return fontIndex >= data.size( );
    }

    public T front() {
        if (isEmpty( )) {
            return null;
        }
        return data.get(fontIndex);
    }

    public static void main(String[] args) {
        MyQueue<Integer> queue = new MyQueue<>( );
        queue.enQueue(5);
        queue.enQueue(13);
        queue.enQueue(8);
        queue.enQueue(2);
        Integer front = queue.front( );
        System.out.println("front = " + front);
        queue.deQueue( );
        front = queue.front( );
        System.out.println("front = " + front);
        queue.deQueue( );
        front = queue.front( );
        System.out.println("front = " + front);
        queue.deQueue( );
        front = queue.front( );
        System.out.println("front = " + front);
        queue.deQueue( );
        front = queue.front( );
        System.out.println("front = " + front);
        queue.deQueue( );
        front = queue.front( );
        System.out.println("front = " + front);
    }
}
